//
//  STGoodsTableView.m
//  赛拓
//
//  Created by 王磊 on 7/29/16.
//  Copyright © 2016 立金所. All rights reserved.
//

#import "STGoodsTableView.h"
#import "STBaseTableViewCell.h"
#import "STCommodityBean.h"
#import "STGoodsTableViewHeaderCell.h"
@interface STGoodsTableView()
//<STBaseViewDelegate>

@property (nonatomic ,strong) NSArray *array;

@property (nonatomic ,strong) NSMutableArray *accessoryArray;
@end
@implementation STGoodsTableView

- (NSMutableArray *)accessoryArray {
    if (!_accessoryArray) {
        _accessoryArray = [NSMutableArray array];
    }
    return _accessoryArray;
}
- (void)commitInit {
    [super commitInit];
    [self.dataArray addObjectsFromArray:@[@"中文名称",@"英文名称",@"CAS号",@"分子式",@"分子量",@"精确质量",@"PSA",@"LOGP",@"产品价格",@"产品描述",]];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    STBaseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"%ld",self.cellType]];
    
    if (!cell) {
        
        cell = [STBaseTableViewCell baseTableViewCell:self.cellType forIndexPath:indexPath];
    }
    
    cell.indexPath = indexPath;
    
    cell.textLabel.text = self.dataArray[indexPath.row];
    
    if (self.accessoryArray.count) {
        
        [cell updateData:self.accessoryArray[indexPath.row]];
    }
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 20 * ST_RATE;
}

- (void)firstLoadData:(id)data {
    
    
    
}


- (NSArray *)array {
    if (!_array) {
        
        _array = @[@"cName",@"eName",@"casNum",@"molFormula",@"molWeight",@"weight",@"pas",@"logp",@"price",@"des",];
    }
    return _array;
}
- (void)updateData:(id)data {
    
    STCommodityBean *goods = data;
    
    [self.accessoryArray addObjectsFromArray:@[goods.name,goods.enName,goods.cas,goods.molecular,goods.molWeight,goods.weight,goods.pas,goods.logp,goods.price,goods.des]];
    
    [self reloadData];
}
- (void)updateHeader:(id)data {
    
    STBaseTableViewCell *headerCell = [STBaseTableViewCell baseTableViewCell:STCellTypeGoodsHeader forIndexPath:nil];
    
    [headerCell updateData:data];
    
    headerCell.frame = CGRectMake(0, 0, ST_SCREEN_WIDTH, [STBaseTableViewCell heightForCell:STCellTypeGoodsHeader withData:nil forIndexPath:nil]);
    
    self.tableHeaderView = headerCell;
}
@end
